package main

func main() {

}

//# link: https://leetcode-cn.com/problems/next-greater-element-i/

func nextGreaterElement(nums1 []int, nums2 []int) (ans []int) {
	// 记录在数组中的位置
	positionMap := make(map[int]int)
	for index, num := range nums2 {
		positionMap[num] = index
	}
	for _, num := range nums1 {
		i := positionMap[num] + 1
		for ; i < len(nums2); i++ {
			if nums2[i] > num {
				ans = append(ans, nums2[i])
				break
			}
		}
		if i == len(nums2) {
			ans = append(ans, -1)
		}
	}
	return ans
}
